<template>
    <div class="app-container">
        <el-dialog :close-on-click-modal="false" :title="title" :visible="open" @close="cancel" width="880px"
            append-to-body>
            <!-- 项目信息表单
            <template v-if="form.pid">
                <el-divider content-position="left"><strong>项目信息</strong></el-divider>
                <el-form :modal="projectForm" disabled ref="projectForm" size="small" :inline="true" label-width="68px">
                    <el-form-item label="客户" prop="custom">
                        <el-input v-model="projectForm.custom" placeholder="请输入客户" />
                    </el-form-item>
                    <el-form-item label="机型" prop="model">
                        <el-input v-model="projectForm.model" placeholder="请输入机型" />
                    </el-form-item>
                    <el-form-item label="项目编码" prop="projectNo">
                        <el-input v-model="projectForm.projectNo" placeholder="请输入项目编码" />
                    </el-form-item>
                    <el-form-item label="专案类别" prop="level">
                        <el-input v-model="projectForm.level" placeholder="请输入专案类别" />
                    </el-form-item>
                    <el-form-item label="芯片组" prop="chipGroup">
                        <el-input v-model="projectForm.chipGroup" placeholder="请输入芯片组" />
                    </el-form-item>
                    <el-form-item label="AD板" prop="adBoard">
                        <el-input v-model="projectForm.adBoard" placeholder="请输入AD板" />
                    </el-form-item>
                    <el-form-item label="LCM/OC" prop="lcmOc">
                        <el-input v-model="projectForm.lcmOc" placeholder="请输入LCM/OC" />
                    </el-form-item>
                    <el-form-item label="电源/适配器" class="labelword" prop="powerSupply">
                        <el-input v-model="projectForm.powerSupply" placeholder="请输入电源/适配器" />
                    </el-form-item>
                    <el-form-item label="恒流板" prop="currentBoard">
                        <el-input v-model="projectForm.currentBoard" placeholder="请输入恒流板" />
                    </el-form-item>
                    <el-form-item label="Arm板" prop="armBoard">
                        <el-input v-model="projectForm.armBoard" placeholder="请输入Arm板" />
                    </el-form-item>
                </el-form>
            </template>

<el-divider content-position="left"><strong>bug信息</strong></el-divider>-->

            <el-row :gutter="50">
                <el-form ref="form" :model="form" :rules="rules" label-width="115px">

                    <el-col :span="12">
                        <el-form-item label="Client name" prop="clientName">
                            <el-radio-group v-model="form.clientName">
                                <el-radio :label="1">所有客户</el-radio>
                                <el-radio :label="2">单一客户</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>


                    <el-col :span="12">
                        <el-form-item label="F/W Version" prop="fwVersion">
                            <el-input v-model="form.fwVersion" clearable placeholder="请输入F/W Version" />
                        </el-form-item>
                    </el-col>



                    <el-col :span="12">
                        <el-form-item label="PanelVersion" prop="panelVersion">
                            <el-input v-model="form.panelVersion" clearable placeholder="请输入Panel Version" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="Scaler" prop="scaler">
                            <el-input v-model="form.scaler" clearable placeholder="请输入scaler" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="ProductStage" prop="productStage">
                            <el-select filterable clearable v-model="form.productStage" placeholder="请选择产品阶段">
                                <el-option v-for="dict in dict.type.oa_product_stage" :key="dict.value"
                                    :label="dict.label" :value="dict.value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="产品线" prop="productLine">
                            <el-select filterable clearable v-model="form.productLine" placeholder="请选择产品线">
                                <el-option v-for="dict in dict.type.oa_product_line" :key="dict.value"
                                    :label="dict.label" :value="dict.value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <!-- <el-col :span="12">
                        <el-form-item label="项目经理" prop="projectManager">
                            <el-select filterable clearable v-model="form.projectManager" placeholder="请选择项目经理">
                                <el-option v-for="item in allUserList" :key="item.userId" :label="item.userName"
                                    :value="item.userName"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col> -->

                    <el-col :span="12">
                        <el-form-item label="研发总监" prop="rdDirector">
                            <el-select filterable clearable v-model="form.rdDirector" placeholder="请选择研发总监">
                                <el-option v-for="item in allUserList" :key="item.userId" :label="item.nickName"
                                    :value="item.userName"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="产品经理" prop="productManager">
                            <el-select filterable clearable v-model="form.productManager" placeholder="请选择产品经理">
                                <el-option v-for="item in allUserList" :key="item.userId" :label="item.nickName"
                                    :value="item.userName"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="DQA主管/经理" prop="dqaManager">
                            <el-select filterable clearable v-model="form.dqaManager" placeholder="请选择DQA主管/经理">
                                <el-option v-for="item in allUserList" :key="item.userId" :label="item.nickName"
                                    :value="item.userName"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    
                    <el-col :span="12">
                        <el-form-item label="总经理签核" prop="managerDecision">
                            <el-radio-group v-model="form.managerDecision">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label=null>否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>


                </el-form>
                <el-col>
                    <div style="width: 100%;text-align: center;" v-show="buttonView">
                        <el-button type="primary" @click="submitForm">确 定</el-button>
                        <el-button @click="cancel">取 消</el-button>
                    </div>
                </el-col>

            </el-row>
        </el-dialog>
    </div>
</template>

<script>
import { listUserAll } from "@/api/system/user"
import { putOAWaive } from "@/api/business/bugs"
export default {
    name: 'PutOaForm',
    dicts: ['problem_type', 'oa_product_stage', 'problem_level', 'oa_product_line'],
    data() {
        return {
            buttonView: true,
            open: false,
            title: "推送OA Waive单审批流程",
            form: {},
            rules: {
                clientName: [
                    { required: true, message: "Client Name不能为空", trigger: "blur" }
                ],
                productStage: [
                    { required: true, message: "product Stage不能为空", trigger: "blur" }
                ],
                panelVersion: [
                    { required: true, message: "Panel Version不能为空", trigger: "blur" }
                ],
                scaler: [
                    { required: true, message: "scaler不能为空", trigger: "blur" }
                ],
                productLine: [
                    { required: true, message: "产品线不能为空", trigger: "blur" }
                ],
                // projectManager: [
                //     { required: true, message: "项目经理不能为空", trigger: "blur" }
                // ],
                rdDirector: [
                    { required: true, message: "研发总监不能为空", trigger: "blur" }
                ],
                productManager: [
                    { required: true, message: "产品经理不能为空", trigger: "blur" }
                ],
                dqaManager: [
                    { required: true, message: "DQA主管不能为空", trigger: "blur" }
                ],
                fwVersion: [
                    { required: true, message: "FW Version不能为空", trigger: "blur" }
                ]
            },
            allUserList: []
        };
    },
    computed: {
    },
    watch: {
    },
    created() {

    },
    methods: {
        //打开推送oa系统填写参数的表单
        openForm(param) {
            this.open = true
            this.form.pid = param.pid
            this.form.bids = param.bids
            this.getSystemUserList()
        },
        submitForm() {
            this.buttonView=false
            this.$refs["form"].validate(valid => {
                if (valid) {
                    this.$modal.loading("正在处理请稍等....")
                    //推送操作
                    putOAWaive(this.form).then(response => {
                        if (response.code === 200) {
                            this.open = false
                            this.$emit('uodateList')
                        }
                        this.$modal.closeLoading()
                        this.$modal.msgSuccess(response.msg);
                        this.buttonView=true
                    }).catch(() => {
                        this.buttonView=true
                        this.open = false
                        this.$emit('uodateList')
                        this.$modal.closeLoading()
                    });
                }
                else{
                    this.buttonView=true
                }

            });
        },
        // 表单重置
        reset() {
            this.form = {
                bids: null,
                pid: null,
                clientName: null,
                productStage: null,
                panelVersion: null,
                scaler: null,
                productLine: null,
                // projectManager: null,
                rdDirector: null,
                productManager: null,
                dqaManager: null,
                managerDecision: "",
            };
            this.resetForm("form");
        },
        // 取消按钮
        cancel() {
            this.reset()
            this.open = false
        },
        //获取系统所有用户数据列表
        getSystemUserList() {
            listUserAll(this.form).then(response => {
                this.allUserList = response.data.filter(item => {
                    return !item.admin
                })
            });
        }
    },

};
</script>

<style scoped></style>
